1 module directx.xaudio2;
2 /**************************************************************************
3  *
4  * Copyright (c) Microsoft Corporation.  All rights reserved.
5  *
6  * File:    xaudio2.h
7  * Content: Declarations for the XAudio2 game audio API.
8  *
9  **************************************************************************/
10 
11 /**************************************************************************
12  *
13  * XAudio2 COM object class and interface IDs.
14  *
15  **************************************************************************/
16 
17 version(Windows):
18 
19 version(XAUDIO_2_8)
20 	version = XAudio;
21 version(XAUDIO_2_9)
22 	version = XAudio;
23 version(XAudio):
24 
25 import std.math;
26 
27 import directx.com;
28 
29 // oops, bad way defining it here
30 //version=DXSDK_2010_6;
31 //version=DXSDK_11_0;
32 version=XAUDIO2_HELPER_FUNCTIONS;
33 
34 // it is outdated and i'm lazy, so maybe later i will upgrade it or remove at all.
35 /*
36 version(DXSDK_2008_3)
37 {
38 // XAudio 2.0 (March 2008 SDK)
39 DEFINE_CLSID!(XAudio2, fac23f48, 31f5, 45a8, b4, 9b, 52, 25, d6, 14, 01, aa);
40 DEFINE_CLSID!(XAudio2_Debug, fac23f48, 31f5, 45a8, b4, 9b, 52, 25, d6, 14, 01, db);
41 }
42 
43 version(DXSDK_2008_6)
44 {
45 // XAudio 2.1 (June 2008 SDK)
46 DEFINE_CLSID!(XAudio2, e21a7345, eb21, 468e, be, 50, 80, 4d, b9, 7c, f7, 08);
47 DEFINE_CLSID!(XAudio2_Debug, f7a76c21, 53d4, 46bb, ac, 53, 8b, 45, 9c, ae, 46, bd);
48 }
49 
50 version(DXSDK_2008_8)
51 {
52 // XAudio 2.2 (August 2008 SDK)
53 DEFINE_CLSID(XAudio2, b802058a, 464a, 42db, bc, 10, b6, 50, d6, f2, 58, 6a);
54 DEFINE_CLSID(XAudio2_Debug, 97dfb7e7, 5161, 4015, 87, a9, c7, 9e, 6a, 19, 52, cc);
55 }
56 
57 version(DXSDK_2008_11)
58 {
59 // XAudio 2.3 (November 2008 SDK)
60 DEFINE_CLSID(XAudio2, 4c5e637a, 16c7, 4de3, 9c, 46, 5e, d2, 21, 81, 96, 2d);
61 DEFINE_CLSID(XAudio2_Debug, ef0aa05d, 8075, 4e5d, be, ad, 45, be, 0c, 3c, cb, b3);
62 }
63 
64 version(DXSDK_2009_3)
65 {
66 // XAudio 2.4 (March 2009 SDK)
67 //DEFINE_CLSID(XAudio2, 03219e78, 5bc3, 44d1, b9, 2e, f6, 3d, 89, cc, 65, 26);
68 //DEFINE_CLSID(XAudio2_Debug, 4256535c, 1ea4, 4d4b, 8a, d5, f9, db, 76, 2e, ca, 9e);
69 }
70 
71 version(DXSDK_2009_8)
72 {
73 // XAudio 2.5 (August 2009 SDK)
74 DEFINE_CLSID(XAudio2, 4c9b6dde, 6809, 46e6, a2, 78, 9b, 6a, 97, 58, 86, 70);
75 DEFINE_CLSID(XAudio2_Debug, 715bdd1a, aa82, 436b, b0, fa, 6a, ce, a3, 9b, d0, a1);
76 }
77 
78 version(DXSDK_2010_2)
79 {
80 // XAudio 2.6 (February 2010 SDK)
81 DEFINE_CLSID(XAudio2, 3eda9b49, 2085, 498b, 9b, b2, 39, a6, 77, 84, 93, de);
82 DEFINE_CLSID(XAudio2_Debug, 47199894, 7cc2, 444d, 98, 73, ce, d2, 56, 2c, c6, 0e);
83 }
84 */
85 
86 version(DXSDK_2010_6)
87 {
88 	// XAudio 2.7 (June 2010 SDK)
89 	// this two should be CLSID but for now leave it as IID
90 	mixin(uuid!(XAudio2,"5a508685-a254-4fba-9b82-9a24b00306af"));
91 	mixin(uuid!(XAudio2_Debug, "db05ea35-0329-4d4b-a53a-6dead03d3852"));
92 
93 	mixin(uuid!(IXAudio2, "8bcf1f58-9fe7-4583-8ac6-e2adc465c8bb"));
94 }
95 
96 version(XAUDIO_2_8)
97 {
98 	// XAudio 2.8 ( Windows 8 )
99 	mixin(uuid!(IXAudio2, "60d8dac8-5aa1-4e8e-b597-2f5e2883d484"));
100 }
101 version(XAUDIO_2_9)
102 {
103 	mixin(uuid!(IXAudio2, "2B02E3CF-2E0B-4ec3-BE45-1B2A3FE7210D"));
104     // mixin(uuid!(IXAudio2Extension, "84ac29bb-d619-44d2-b197-e4acf7df3ed6"));
105 }
106 
107 // Ignore the rest of this header if only the GUID definitions were requested
108 version(GUID_DEFS_ONLY)
109 {
110 }
111 else
112 {
113 	enum AUDIO_STREAM_CATEGORY
114 	{
115 		AudioCategory_Other,
116 		AudioCategory_ForegroundOnlyMedia,
117 		AudioCategory_BackgroundCapableMedia,
118 		AudioCategory_Communications,
119 		AudioCategory_Alerts,
120 		AudioCategory_SoundEffects,
121 		AudioCategory_GameEffects,
122 		AudioCategory_GameMedia,
123 		AudioCategory_GameChat,
124 		AudioCategory_Speech,
125 		AudioCategory_Movie,
126 		AudioCategory_Media,
127 		AudioCategory_FarFieldSpeech,
128 		AudioCategory_UniformSpeech,
129 		AudioCategory_VoiceTyping
130 	}
131 
132 	// required for uuid template
133 	interface XAudio2 : IUnknown{}
134 	interface XAudio2_Debug : IUnknown{}	
135 
136 	version(XBOX)
137 		import xbox.xobjbase;   // Xbox COM declarations (IUnknown, etc)
138 	else
139 		import directx.com;   // Windows COM declarations
140 
141 	// All structures defined in this file use tight field packing
142 	align(1):
143 
144 
145 	/**************************************************************************
146 	*
147 	* XAudio2 constants, flags and error codes.
148 	*
149 	**************************************************************************/
150 
151 	// Numeric boundary values
152 	enum XAUDIO2_MAX_BUFFER_BYTES        = 0x80000000;    // Maximum bytes allowed in a source buffer
153 	enum XAUDIO2_MAX_QUEUED_BUFFERS      = 64;            // Maximum buffers allowed in a voice queue
154 	enum XAUDIO2_MAX_BUFFERS_SYSTEM      = 2;             // Maximum buffers allowed for system threads (Xbox 360 only)
155 	enum XAUDIO2_MAX_AUDIO_CHANNELS      = 64;            // Maximum channels in an audio stream
156 	enum XAUDIO2_MIN_SAMPLE_RATE         = 1000;          // Minimum audio sample rate supported
157 	enum XAUDIO2_MAX_SAMPLE_RATE         = 200000;        // Maximum audio sample rate supported
158 	enum XAUDIO2_MAX_VOLUME_LEVEL        = 16777216.0f;   // Maximum acceptable volume level (2^24)
159 	enum XAUDIO2_MIN_FREQ_RATIO          = (1/1024.0f);   // Minimum SetFrequencyRatio argument
160 	enum XAUDIO2_MAX_FREQ_RATIO          = 1024.0f;       // Maximum MaxFrequencyRatio argument
161 	enum XAUDIO2_DEFAULT_FREQ_RATIO      = 2.0f;          // Default MaxFrequencyRatio argument
162 	enum XAUDIO2_MAX_FILTER_ONEOVERQ     = 1.5f;          // Maximum XAUDIO2_FILTER_PARAMETERS.OneOverQ
163 	enum XAUDIO2_MAX_FILTER_FREQUENCY    = 1.0f;          // Maximum XAUDIO2_FILTER_PARAMETERS.Frequency
164 	enum XAUDIO2_MAX_LOOP_COUNT          = 254;           // Maximum non-infinite XAUDIO2_BUFFER.LoopCount
165 	enum XAUDIO2_MAX_INSTANCES           = 8;             // Maximum simultaneous XAudio2 objects on Xbox 360
166 
167 	// For XMA voices on Xbox 360 there is an additional restriction on the MaxFrequencyRatio
168 	// argument and the voice's sample rate: the product of these numbers cannot exceed 600000
169 	// for one-channel voices or 300000 for voices with more than one channel.
170 	enum XAUDIO2_MAX_RATIO_TIMES_RATE_XMA_MONO         = 600000;
171 	enum XAUDIO2_MAX_RATIO_TIMES_RATE_XMA_MULTICHANNEL = 300000;
172 
173 	// Numeric values with special meanings
174 	enum XAUDIO2_COMMIT_NOW              = 0;              // Used as an OperationSet argument
175 	enum XAUDIO2_COMMIT_ALL              = 0;              // Used in IXAudio2::CommitChanges
176 	enum XAUDIO2_INVALID_OPSET           = cast(uint)(-1); // Not allowed for OperationSet arguments
177 	enum XAUDIO2_NO_LOOP_REGION          = 0;              // Used in XAUDIO2_BUFFER.LoopCount
178 	enum XAUDIO2_LOOP_INFINITE           = 255;            // Used in XAUDIO2_BUFFER.LoopCount
179 	enum XAUDIO2_DEFAULT_CHANNELS        = 0;              // Used in CreateMasteringVoice
180 	enum XAUDIO2_DEFAULT_SAMPLERATE      = 0;              // Used in CreateMasteringVoice
181 
182 	// Flags
183 	enum XAUDIO2_DEBUG_ENGINE            = 0x0001;         // Used in XAudio2Create on Windows only
184 	enum XAUDIO2_VOICE_NOPITCH           = 0x0002;         // Used in IXAudio2::CreateSourceVoice
185 	enum XAUDIO2_VOICE_NOSRC             = 0x0004;         // Used in IXAudio2::CreateSourceVoice
186 	enum XAUDIO2_VOICE_USEFILTER         = 0x0008;         // Used in IXAudio2::CreateSource/SubmixVoice
187 	enum XAUDIO2_VOICE_MUSIC             = 0x0010;         // Used in IXAudio2::CreateSourceVoice
188 	enum XAUDIO2_PLAY_TAILS              = 0x0020;         // Used in IXAudio2SourceVoice::Stop
189 	enum XAUDIO2_END_OF_STREAM           = 0x0040;         // Used in XAUDIO2_BUFFER.Flags
190 	enum XAUDIO2_SEND_USEFILTER          = 0x0080;         // Used in XAUDIO2_SEND_DESCRIPTOR.Flags
191 	enum XAUDIO2_VOICE_NOSAMPLESPLAYED   = 0x0100;	       // Used in IXAudio2SourceVoice::GetState
192 	enum XAUDIO2_STOP_ENGINE_WHEN_IDLE   = 0x2000;	       // Used in XAudio2Create to force the engine to Stop when no source voices are Started, and Start when a voice is Started
193 	enum XAUDIO2_1024_QUANTUM            = 0x8000;	       // Used in XAudio2Create to specify nondefault processing quantum of 21.33 ms (1024 samples at 48KHz)
194 	enum XAUDIO2_NO_VIRTUAL_AUDIO_CLIENT = 0x10000;	       // Used in CreateMasteringVoice to create a virtual audio client
195 
196 
197 	// Default parameters for the built-in filter
198 	enum XAUDIO2_DEFAULT_FILTER_TYPE      = LowPassFilter;
199 	enum XAUDIO2_DEFAULT_FILTER_FREQUENCY = XAUDIO2_MAX_FILTER_FREQUENCY;
200 	enum XAUDIO2_DEFAULT_FILTER_ONEOVERQ  = 1.0f;
201 
202 	// Internal XAudio2 constants
203 	version(XBOX)
204 	{
205 		enum XAUDIO2_QUANTUM_NUMERATOR   = 2;              // On Xbox 360, XAudio2 processes audio
206 		enum XAUDIO2_QUANTUM_DENOMINATOR = 375;            //  in 5.333ms chunks (= 2/375 seconds)
207 	}
208 	else
209 	{
210 		enum XAUDIO2_QUANTUM_NUMERATOR   = 1;              // On Windows, XAudio2 processes audio
211 		enum XAUDIO2_QUANTUM_DENOMINATOR = 100;            //  in 10ms chunks (= 1/100 seconds)
212 	}
213 	enum XAUDIO2_QUANTUM_MS = (1000.0f * XAUDIO2_QUANTUM_NUMERATOR / XAUDIO2_QUANTUM_DENOMINATOR);
214 
215 	// XAudio2 error codes
216 	enum FACILITY_XAUDIO2 = 0x896;
217 	enum XAUDIO2_E_INVALID_CALL          = 0x88960001;     // An API call or one of its arguments was illegal
218 	enum XAUDIO2_E_XMA_DECODER_ERROR     = 0x88960002;     // The XMA hardware suffered an unrecoverable error
219 	enum XAUDIO2_E_XAPO_CREATION_FAILED  = 0x88960003;     // XAudio2 failed to initialize an XAPO effect
220 	enum XAUDIO2_E_DEVICE_INVALIDATED    = 0x88960004;     // An audio device became unusable (unplugged, etc)
221 
222 
223 	/**************************************************************************
224 	*
225 	* XAudio2 structures and enumerations.
226 	*
227 	**************************************************************************/
228 
229 	// Used in IXAudio2::Initialize
230 	version(XBOX) {
231 		enum XAUDIO2_XBOX_HWTHREAD_SPECIFIER
232 		{
233 			XboxThread0 = 0x01,
234 			XboxThread1 = 0x02,
235 			XboxThread2 = 0x04,
236 			XboxThread3 = 0x08,
237 			XboxThread4 = 0x10,
238 			XboxThread5 = 0x20,
239 			XAUDIO2_ANY_PROCESSOR = XboxThread4,
240 			XAUDIO2_DEFAULT_PROCESSOR = XAUDIO2_ANY_PROCESSOR
241 		} 
242 		alias XAUDIO2_XBOX_HWTHREAD_SPECIFIER XAUDIO2_PROCESSOR;
243 	}
244 	else {
245 		alias XAUDIO2_WINDOWS_PROCESSOR_SPECIFIER = int;
246 		enum : XAUDIO2_WINDOWS_PROCESSOR_SPECIFIER
247 		{
248 			Processor1  = 0x00000001,
249 			Processor2  = 0x00000002,
250 			Processor3  = 0x00000004,
251 			Processor4  = 0x00000008,
252 			Processor5  = 0x00000010,
253 			Processor6  = 0x00000020,
254 			Processor7  = 0x00000040,
255 			Processor8  = 0x00000080,
256 			Processor9  = 0x00000100,
257 			Processor10 = 0x00000200,
258 			Processor11 = 0x00000400,
259 			Processor12 = 0x00000800,
260 			Processor13 = 0x00001000,
261 			Processor14 = 0x00002000,
262 			Processor15 = 0x00004000,
263 			Processor16 = 0x00008000,
264 			Processor17 = 0x00010000,
265 			Processor18 = 0x00020000,
266 			Processor19 = 0x00040000,
267 			Processor20 = 0x00080000,
268 			Processor21 = 0x00100000,
269 			Processor22 = 0x00200000,
270 			Processor23 = 0x00400000,
271 			Processor24 = 0x00800000,
272 			Processor25 = 0x01000000,
273 			Processor26 = 0x02000000,
274 			Processor27 = 0x04000000,
275 			Processor28 = 0x08000000,
276 			Processor29 = 0x10000000,
277 			Processor30 = 0x20000000,
278 			Processor31 = 0x40000000,
279 			Processor32 = 0x80000000,
280 			XAUDIO2_ANY_PROCESSOR = 0xffffffff,
281 			XAUDIO2_DEFAULT_PROCESSOR = XAUDIO2_ANY_PROCESSOR
282 		} 
283 		alias XAUDIO2_WINDOWS_PROCESSOR_SPECIFIER XAUDIO2_PROCESSOR;
284 	}
285 
286 
287 	// Used in XAUDIO2_DEVICE_DETAILS below to describe the types of applications
288 	// that the user has specified each device as a default for.  0 means that the
289 	// device isn't the default for any role.
290     alias DWORD XAUDIO2_DEVICE_ROLE;
291 	enum : XAUDIO2_DEVICE_ROLE
292 	{
293 		NotDefaultDevice            = 0x0,
294 		DefaultConsoleDevice        = 0x1,
295 		DefaultMultimediaDevice     = 0x2,
296 		DefaultCommunicationsDevice = 0x4,
297 		DefaultGameDevice           = 0x8,
298 		GlobalDefaultDevice         = 0xf,
299 		InvalidDeviceRole = ~GlobalDefaultDevice
300 	}
301 
302 	// Returned by IXAudio2::GetDeviceDetails
303 	struct XAUDIO2_DEVICE_DETAILS
304 	{
305 		WCHAR[256] DeviceID;                // String identifier for the audio device.
306 		WCHAR[256] DisplayName;             // Friendly name suitable for display to a human.
307 		XAUDIO2_DEVICE_ROLE Role;           // Roles that the device should be used for.
308 		WAVEFORMATEXTENSIBLE OutputFormat;  // The device's native PCM audio output format.
309 	}
310 
311 	// Returned by IXAudio2Voice::GetVoiceDetails
312 	struct XAUDIO2_VOICE_DETAILS
313 	{	
314 		UINT32 CreationFlags;               // Flags the voice was created with.
315 		UINT32 InputChannels;               // Channels in the voice's input audio.
316 		UINT32 InputSampleRate;             // Sample rate of the voice's input audio.
317 	}
318 
319 	// Used in XAUDIO2_VOICE_SENDS below
320 	struct XAUDIO2_SEND_DESCRIPTOR
321 	{
322 		UINT32 Flags;                       // Either 0 or XAUDIO2_SEND_USEFILTER.
323 		IXAudio2Voice pOutputVoice;        // This send's destination voice.
324 	}
325 
326 	// Used in the voice creation functions and in IXAudio2Voice::SetOutputVoices
327 	struct XAUDIO2_VOICE_SENDS
328 	{
329 		UINT32 SendCount;                   // Number of sends from this voice.
330 		XAUDIO2_SEND_DESCRIPTOR* pSends;    // Array of SendCount send descriptors.
331 	}
332 
333 	// Used in XAUDIO2_EFFECT_CHAIN below
334 	struct XAUDIO2_EFFECT_DESCRIPTOR
335 	{
336 		IUnknown pEffect;                  // Pointer to the effect object's IUnknown interface.
337 		BOOL InitialState;                  // TRUE if the effect should begin in the enabled state.
338 		UINT32 OutputChannels;              // How many output channels the effect should produce.
339 	}
340 
341 	// Used in the voice creation functions and in IXAudio2Voice::SetEffectChain
342 	struct XAUDIO2_EFFECT_CHAIN
343 	{
344 		UINT32 EffectCount;                 // Number of effects in this voice's effect chain.
345 		XAUDIO2_EFFECT_DESCRIPTOR* pEffectDescriptors; // Array of effect descriptors.
346 	}
347 
348 	// Used in XAUDIO2_FILTER_PARAMETERS below
349 	alias XAUDIO2_FILTER_TYPE = uint;
350 	enum : XAUDIO2_FILTER_TYPE
351 	{
352 		LowPassFilter,                      // Attenuates frequencies above the cutoff frequency.
353 		BandPassFilter,                     // Attenuates frequencies outside a given range.
354 		HighPassFilter,                     // Attenuates frequencies below the cutoff frequency.
355 		NotchFilter                         // Attenuates frequencies inside a given range.
356 	}
357 
358 	// Used in IXAudio2Voice::Set/GetFilterParameters and Set/GetOutputFilterParameters
359 	struct XAUDIO2_FILTER_PARAMETERS
360 	{
361 		XAUDIO2_FILTER_TYPE Type;           // Low-pass, band-pass or high-pass.
362 		float Frequency;                    // Radian frequency (2 * sin(pi*CutoffFrequency/SampleRate));
363 		//  must be >= 0 and <= XAUDIO2_MAX_FILTER_FREQUENCY
364 		//  (giving a maximum CutoffFrequency of SampleRate/6).
365 		float OneOverQ;                     // Reciprocal of the filter's quality factor Q;
366 		//  must be > 0 and <= XAUDIO2_MAX_FILTER_ONEOVERQ.
367 	}
368 
369 	// Used in IXAudio2SourceVoice::SubmitSourceBuffer
370 	struct XAUDIO2_BUFFER
371 	{
372 		UINT32 Flags;                       // Either 0 or XAUDIO2_END_OF_STREAM.
373 		UINT32 AudioBytes;                  // Size of the audio data buffer in bytes.
374 		const (ubyte)* pAudioData;             // Pointer to the audio data buffer.
375 		UINT32 PlayBegin;                   // First sample in this buffer to be played.
376 		UINT32 PlayLength;                  // Length of the region to be played in samples,
377 		//  or 0 to play the whole buffer.
378 		UINT32 LoopBegin;                   // First sample of the region to be looped.
379 		UINT32 LoopLength;                  // Length of the desired loop region in samples,
380 		//  or 0 to loop the entire buffer.
381 		UINT32 LoopCount;                   // Number of times to repeat the loop region,
382 		//  or XAUDIO2_LOOP_INFINITE to loop forever.
383 		void* pContext;                     // Context value to be passed back in callbacks.
384 	}
385 
386 	// Used in IXAudio2SourceVoice::SubmitSourceBuffer when submitting XWMA data.
387 	// NOTE: If an XWMA sound is submitted in more than one buffer, each buffer's
388 	// pDecodedPacketCumulativeBytes[PacketCount-1] value must be subtracted from
389 	// all the entries in the next buffer's pDecodedPacketCumulativeBytes array.
390 	// And whether a sound is submitted in more than one buffer or not, the final
391 	// buffer of the sound should use the XAUDIO2_END_OF_STREAM flag, or else the
392 	// client must call IXAudio2SourceVoice::Discontinuity after submitting it.
393 	struct XAUDIO2_BUFFER_WMA
394 	{
395 		const (UINT32)* pDecodedPacketCumulativeBytes; // Decoded packet's cumulative size array.
396 		//  Each element is the number of bytes accumulated
397 		//  when the corresponding XWMA packet is decoded in
398 		//  order.  The array must have PacketCount elements.
399 		UINT32 PacketCount;                          // Number of XWMA packets submitted. Must be >= 1 and
400 		//  divide evenly into XAUDIO2_BUFFER.AudioBytes.
401 	}
402 
403 	// Returned by IXAudio2SourceVoice::GetState
404 	struct XAUDIO2_VOICE_STATE
405 	{
406 		void* pCurrentBufferContext;        // The pContext value provided in the XAUDIO2_BUFFER
407 		//  that is currently being processed, or NULL if
408 		//	there are no buffers in the queue.
409 		UINT32 BuffersQueued;               // Number of buffers currently queued on the voice
410 		//  (including the one that is being processed).
411 		UINT64 SamplesPlayed;               // Total number of samples produced by the voice since
412 		//  it began processing the current audio stream.
413 	}
414 
415 	// Returned by IXAudio2::GetPerformanceData
416 	struct XAUDIO2_PERFORMANCE_DATA
417 	{
418 		// CPU usage information
419 		UINT64 AudioCyclesSinceLastQuery;   // CPU cycles spent on audio processing since the
420 		//  last call to StartEngine or GetPerformanceData.
421 		UINT64 TotalCyclesSinceLastQuery;   // Total CPU cycles elapsed since the last call
422 		//  (only counts the CPU XAudio2 is running on).
423 		UINT32 MinimumCyclesPerQuantum;     // Fewest CPU cycles spent processing any one
424 		//  audio quantum since the last call.
425 		UINT32 MaximumCyclesPerQuantum;     // Most CPU cycles spent processing any one
426 		//  audio quantum since the last call.
427 
428 		// Memory usage information
429 		UINT32 MemoryUsageInBytes;          // Total heap space currently in use.
430 
431 		// Audio latency and glitching information
432 		UINT32 CurrentLatencyInSamples;     // Minimum delay from when a sample is read from a
433 		//  source buffer to when it reaches the speakers.
434 		UINT32 GlitchesSinceEngineStarted;  // Audio dropouts since the engine was started.
435 
436 		// Data about XAudio2's current workload
437 		UINT32 ActiveSourceVoiceCount;      // Source voices currently playing.
438 		UINT32 TotalSourceVoiceCount;       // Source voices currently existing.
439 		UINT32 ActiveSubmixVoiceCount;      // Submix voices currently playing/existing.
440 
441 		UINT32 ActiveResamplerCount;        // Resample xAPOs currently active.
442 		UINT32 ActiveMatrixMixCount;        // MatrixMix xAPOs currently active.
443 
444 		// Usage of the hardware XMA decoder (Xbox 360 only)
445 		UINT32 ActiveXmaSourceVoices;       // Number of source voices decoding XMA data.
446 		UINT32 ActiveXmaStreams;            // A voice can use more than one XMA stream.
447 	}
448 
449 	// Used in IXAudio2::SetDebugConfiguration
450 	struct XAUDIO2_DEBUG_CONFIGURATION
451 	{
452 		UINT32 TraceMask;                   // Bitmap of enabled debug message types.
453 		UINT32 BreakMask;                   // Message types that will break into the debugger.
454 		BOOL LogThreadID;                   // Whether to log the thread ID with each message.
455 		BOOL LogFileline;                   // Whether to log the source file and line number.
456 		BOOL LogFunctionName;               // Whether to log the function name.
457 		BOOL LogTiming;                     // Whether to log message timestamps.
458 	}
459 
460 	// Values for the TraceMask and BreakMask bitmaps.  Only ERRORS and WARNINGS
461 	// are valid in BreakMask.  WARNINGS implies ERRORS, DETAIL implies INFO, and
462 	// FUNC_CALLS implies API_CALLS.  By default, TraceMask is ERRORS and WARNINGS
463 	// and all the other settings are zero.
464 	enum XAUDIO2_LOG_ERRORS     = 0x0001;   // For handled errors with serious effects.
465 	enum XAUDIO2_LOG_WARNINGS   = 0x0002;   // For handled errors that may be recoverable.
466 	enum XAUDIO2_LOG_INFO       = 0x0004;   // Informational chit-chat (e.g. state changes).
467 	enum XAUDIO2_LOG_DETAIL     = 0x0008;   // More detailed chit-chat.
468 	enum XAUDIO2_LOG_API_CALLS  = 0x0010;   // Public API function entries and exits.
469 	enum XAUDIO2_LOG_FUNC_CALLS = 0x0020;   // Internal function entries and exits.
470 	enum XAUDIO2_LOG_TIMING     = 0x0040;   // Delays detected and other timing data.
471 	enum XAUDIO2_LOG_LOCKS      = 0x0080;   // Usage of critical sections and mutexes.
472 	enum XAUDIO2_LOG_MEMORY     = 0x0100;   // Memory heap usage information.
473 	enum XAUDIO2_LOG_STREAMING  = 0x1000;   // Audio streaming information.
474 
475 
476 	/**************************************************************************
477 	*
478 	* IXAudio2: Top-level XAudio2 COM interface.
479 	*
480 	**************************************************************************/
481 	interface IXAudio2 : IUnknown
482 	{
483 		extern(Windows):
484 		version(DXSDK_2010_6)
485 		{
486 		// NAME: IXAudio2::GetDeviceCount
487 		// DESCRIPTION: Returns the number of audio output devices available.
488 		//
489 		// ARGUMENTS:
490 		//  pCount - Returns the device count.
491 		//
492 		HRESULT GetDeviceCount(UINT32* pCount);
493 
494 		// NAME: IXAudio2::GetDeviceDetails
495 		// DESCRIPTION: Returns information about the device with the given index.
496 		//
497 		// ARGUMENTS:
498 		//  Index - Index of the device to be queried.
499 		//  pDeviceDetails - Returns the device details.
500 		//
501 		HRESULT GetDeviceDetails (UINT32 Index, XAUDIO2_DEVICE_DETAILS* pDeviceDetails);
502 
503 		// NAME: IXAudio2::Initialize
504 		// DESCRIPTION: Sets global XAudio2 parameters and prepares it for use.
505 		//
506 		// ARGUMENTS:
507 		//  Flags - Flags specifying the XAudio2 object's behavior.  Currently unused.
508 		//  XAudio2Processor - An XAUDIO2_PROCESSOR enumeration value that specifies
509 		//  the hardware thread (Xbox) or processor (Windows) that XAudio2 will use.
510 		//  The enumeration values are platform-specific; platform-independent code
511 		//  can use XAUDIO2_DEFAULT_PROCESSOR to use the default on each platform.
512 		//
513 		HRESULT Initialize (
514 							UINT32 Flags = 0,
515 							XAUDIO2_PROCESSOR XAudio2Processor = XAUDIO2_DEFAULT_PROCESSOR); // XAUDIO2_WINDOWS_PROCESSOR_SPECIFIER.XAUDIO2_DEFAULT_PROCESSOR );
516 		}
517 
518 		// NAME: IXAudio2::RegisterForCallbacks
519 		// DESCRIPTION: Adds a new client to receive XAudio2's engine callbacks.
520 		//
521 		// ARGUMENTS:
522 		//  pCallback - Callback interface to be called during each processing pass.
523 		//
524 		HRESULT RegisterForCallbacks (IXAudio2EngineCallback pCallback);
525 
526 		// NAME: IXAudio2::UnregisterForCallbacks
527 		// DESCRIPTION: Removes an existing receiver of XAudio2 engine callbacks.
528 		//
529 		// ARGUMENTS:
530 		//  pCallback - Previously registered callback interface to be removed.
531 		//
532 		void UnregisterForCallbacks(IXAudio2EngineCallback pCallback);
533 
534 		// NAME: IXAudio2::CreateSourceVoice
535 		// DESCRIPTION: Creates and configures a source voice.
536 		//
537 		// ARGUMENTS:
538 		//  ppSourceVoice - Returns the new object's IXAudio2SourceVoice interface.
539 		//  pSourceFormat - Format of the audio that will be fed to the voice.
540 		//  Flags - XAUDIO2_VOICE flags specifying the source voice's behavior.
541 		//  MaxFrequencyRatio - Maximum SetFrequencyRatio argument to be allowed.
542 		//	pCallback - Optional pointer to a client-provided callback interface.
543 		//  pSendList - Optional list of voices this voice should send audio to.
544 		//  pEffectChain - Optional list of effects to apply to the audio data.
545 		//
546 		HRESULT CreateSourceVoice (IXAudio2SourceVoice* ppSourceVoice,
547 								   const (WAVEFORMATEX)* pSourceFormat,
548 								   UINT32 Flags = 0,
549 								   float MaxFrequencyRatio = XAUDIO2_DEFAULT_FREQ_RATIO,
550 								   IXAudio2VoiceCallback pCallback = null,
551 								   const (XAUDIO2_VOICE_SENDS)* pSendList = null,
552 								   const (XAUDIO2_EFFECT_CHAIN)* pEffectChain = null);
553 
554 		// NAME: IXAudio2::CreateSubmixVoice
555 		// DESCRIPTION: Creates and configures a submix voice.
556 		//
557 		// ARGUMENTS:
558 		//  ppSubmixVoice - Returns the new object's IXAudio2SubmixVoice interface.
559 		//  InputChannels - Number of channels in this voice's input audio data.
560 		//  InputSampleRate - Sample rate of this voice's input audio data.
561 		//  Flags - XAUDIO2_VOICE flags specifying the submix voice's behavior.
562 		//  ProcessingStage - Arbitrary number that determines the processing order.
563 		//  pSendList - Optional list of voices this voice should send audio to.
564 		//  pEffectChain - Optional list of effects to apply to the audio data.
565 		//
566 		HRESULT CreateSubmixVoice (IXAudio2SubmixVoice* ppSubmixVoice,
567 								   UINT32 InputChannels, UINT32 InputSampleRate,
568 								   UINT32 Flags = 0, UINT32 ProcessingStage = 0,
569 								   const (XAUDIO2_VOICE_SENDS)* pSendList = null,
570 								   const (XAUDIO2_EFFECT_CHAIN)* pEffectChain = null);
571 
572 
573 		// NAME: IXAudio2::CreateMasteringVoice
574 		// DESCRIPTION: Creates and configures a mastering voice.
575 		//
576 		// ARGUMENTS:
577 		//  ppMasteringVoice - Returns the new object's IXAudio2MasteringVoice interface.
578 		//  InputChannels - Number of channels in this voice's input audio data.
579 		//  InputSampleRate - Sample rate of this voice's input audio data.
580 		//  Flags - XAUDIO2_VOICE flags specifying the mastering voice's behavior.
581 		//  DeviceIndex - Identifier of the device to receive the output audio.
582 		//  pEffectChain - Optional list of effects to apply to the audio data.
583 		//
584 		HRESULT CreateMasteringVoice (IXAudio2MasteringVoice* ppMasteringVoice,
585 									  UINT32 InputChannels = XAUDIO2_DEFAULT_CHANNELS,
586 									  UINT32 InputSampleRate = XAUDIO2_DEFAULT_SAMPLERATE,
587 									  UINT32 Flags = 0, UINT32 DeviceIndex = 0,
588 									  const (XAUDIO2_EFFECT_CHAIN)* pEffectChain = null,
589 									  AUDIO_STREAM_CATEGORY StreamCategory = AUDIO_STREAM_CATEGORY.AudioCategory_GameEffects);
590 
591 		// NAME: IXAudio2::StartEngine
592 		// DESCRIPTION: Creates and starts the audio processing thread.
593 		//
594 		HRESULT StartEngine ();
595 
596 		// NAME: IXAudio2::StopEngine
597 		// DESCRIPTION: Stops and destroys the audio processing thread.
598 		//
599 		void StopEngine ();
600 
601 		// NAME: IXAudio2::CommitChanges
602 		// DESCRIPTION: Atomically applies a set of operations previously tagged
603 		//              with a given identifier.
604 		//
605 		// ARGUMENTS:
606 		//  OperationSet - Identifier of the set of operations to be applied.
607 		//
608 		HRESULT CommitChanges (UINT32 OperationSet);
609 
610 		// NAME: IXAudio2::GetPerformanceData
611 		// DESCRIPTION: Returns current resource usage details: memory, CPU, etc.
612 		//
613 		// ARGUMENTS:
614 		//  pPerfData - Returns the performance data structure.
615 		//
616 		void GetPerformanceData (XAUDIO2_PERFORMANCE_DATA* pPerfData);
617 
618 		// NAME: IXAudio2::SetDebugConfiguration
619 		// DESCRIPTION: Configures XAudio2's debug output (in debug builds only).
620 		//
621 		// ARGUMENTS:
622 		//  pDebugConfiguration - Structure describing the debug output behavior.
623 		//	pReserved - Optional parameter; must be NULL.
624 		//
625 		void SetDebugConfiguration (const (XAUDIO2_DEBUG_CONFIGURATION)* pDebugConfiguration,
626 									void* pReserved = null);
627 	}
628 
629 
630 	/**************************************************************************
631 	*
632 	* IXAudio2Voice: Base voice management interface.
633 	*
634 	**************************************************************************/
635 
636 	extern(C++) interface IXAudio2Voice
637 	{
638 			extern(Windows):
639 			/* NAME: IXAudio2Voice::GetVoiceDetails
640 			// DESCRIPTION: Returns the basic characteristics of this voice.
641 			//
642 			// ARGUMENTS:
643 			//  pVoiceDetails - Returns the voice's details.
644 			*/
645 			void GetVoiceDetails (XAUDIO2_VOICE_DETAILS* pVoiceDetails);
646 
647 			/* NAME: IXAudio2Voice::SetOutputVoices
648 			// DESCRIPTION: Replaces the set of submix/mastering voices that receive
649 			//              this voice's output.
650 			//
651 			// ARGUMENTS:
652 			//  pSendList - Optional list of voices this voice should send audio to.
653 			*/
654 			HRESULT SetOutputVoices (const (XAUDIO2_VOICE_SENDS)* pSendList);
655 
656 			/* NAME: IXAudio2Voice::SetEffectChain
657 			// DESCRIPTION: Replaces this voice's current effect chain with a new one.
658 			//
659 			// ARGUMENTS:
660 			//  pEffectChain - Structure describing the new effect chain to be used.
661 			*/
662 			HRESULT SetEffectChain (const (XAUDIO2_EFFECT_CHAIN)* pEffectChain);
663 
664 			/* NAME: IXAudio2Voice::EnableEffect
665 			// DESCRIPTION: Enables an effect in this voice's effect chain.
666 			//
667 			// ARGUMENTS:
668 			//  EffectIndex - Index of an effect within this voice's effect chain.
669 			//  OperationSet - Used to identify this call as part of a deferred batch.
670 			*/
671 			HRESULT EnableEffect (UINT32 EffectIndex,
672 									UINT32 OperationSet = XAUDIO2_COMMIT_NOW);
673 
674 			/* NAME: IXAudio2Voice::DisableEffect
675 			// DESCRIPTION: Disables an effect in this voice's effect chain.
676 			//
677 			// ARGUMENTS:
678 			//  EffectIndex - Index of an effect within this voice's effect chain.
679 			//  OperationSet - Used to identify this call as part of a deferred batch.
680 			*/
681 			HRESULT DisableEffect (UINT32 EffectIndex,
682 									UINT32 OperationSet = XAUDIO2_COMMIT_NOW);
683 
684 			/* NAME: IXAudio2Voice::GetEffectState
685 			// DESCRIPTION: Returns the running state of an effect.
686 			//
687 			// ARGUMENTS:
688 			//  EffectIndex - Index of an effect within this voice's effect chain.
689 			//  pEnabled - Returns the enabled/disabled state of the given effect.
690 			*/
691 			void GetEffectState (UINT32 EffectIndex, /*out*/ BOOL* pEnabled);
692 
693 			/* NAME: IXAudio2Voice::SetEffectParameters
694 			// DESCRIPTION: Sets effect-specific parameters.
695 			//
696 			// REMARKS: Unlike IXAPOParameters::SetParameters, this method may
697 			//          be called from any thread.  XAudio2 implements
698 			//          appropriate synchronization to copy the parameters to the
699 			//          realtime audio processing thread.
700 			//
701 			// ARGUMENTS:
702 			//  EffectIndex - Index of an effect within this voice's effect chain.
703 			//  pParameters - Pointer to an effect-specific parameters block.
704 			//  ParametersByteSize - Size of the pParameters array  in bytes.
705 			//  OperationSet - Used to identify this call as part of a deferred batch.
706 			*/
707 
708 			HRESULT SetEffectParameters (UINT32 EffectIndex,
709 											const (void)* pParameters,
710 											UINT32 ParametersByteSize,
711 											UINT32 OperationSet = XAUDIO2_COMMIT_NOW);
712 
713 			/* NAME: IXAudio2Voice::GetEffectParameters
714 			// DESCRIPTION: Obtains the current effect-specific parameters.
715 			//
716 			// ARGUMENTS:
717 			//  EffectIndex - Index of an effect within this voice's effect chain.
718 			//  pParameters - Returns the current values of the effect-specific parameters.
719 			//  ParametersByteSize - Size of the pParameters array in bytes.
720 			*/
721 			HRESULT GetEffectParameters ( UINT32 EffectIndex,
722 											void* pParameters,
723 											UINT32 ParametersByteSize);
724 
725 			/* NAME: IXAudio2Voice::SetFilterParameters
726 			// DESCRIPTION: Sets this voice's filter parameters.
727 			//
728 			// ARGUMENTS:
729 			//  pParameters - Pointer to the filter's parameter structure.
730 			//  OperationSet - Used to identify this call as part of a deferred batch.
731 			*/
732 			HRESULT SetFilterParameters ( const(XAUDIO2_FILTER_PARAMETERS)* pParameters,
733 											UINT32 OperationSet = XAUDIO2_COMMIT_NOW);
734 
735 			/* NAME: IXAudio2Voice::GetFilterParameters
736 			// DESCRIPTION: Returns this voice's current filter parameters.
737 			//
738 			// ARGUMENTS:
739 			//  pParameters - Returns the filter parameters.
740 			*/
741 			void GetFilterParameters (XAUDIO2_FILTER_PARAMETERS* pParameters);
742 
743 			/* NAME: IXAudio2Voice::SetOutputFilterParameters
744 			// DESCRIPTION: Sets the filter parameters on one of this voice's sends.
745 			//
746 			// ARGUMENTS:
747 			//  pDestinationVoice - Destination voice of the send whose filter parameters will be set.
748 			//  pParameters - Pointer to the filter's parameter structure.
749 			//  OperationSet - Used to identify this call as part of a deferred batch.
750 			*/
751 			HRESULT SetOutputFilterParameters (IXAudio2Voice pDestinationVoice,
752 												const (XAUDIO2_FILTER_PARAMETERS)* pParameters,
753 												UINT32 OperationSet = XAUDIO2_COMMIT_NOW);
754 
755 			/* NAME: IXAudio2Voice::GetOutputFilterParameters
756 			// DESCRIPTION: Returns the filter parameters from one of this voice's sends.
757 			//
758 			// ARGUMENTS:
759 			//  pDestinationVoice - Destination voice of the send whose filter parameters will be read.
760 			//  pParameters - Returns the filter parameters.
761 			*/
762 			void GetOutputFilterParameters (IXAudio2Voice pDestinationVoice,
763 												XAUDIO2_FILTER_PARAMETERS* pParameters); 
764 
765 			/* NAME: IXAudio2Voice::SetVolume
766 			// DESCRIPTION: Sets this voice's overall volume level.
767 			//
768 			// ARGUMENTS:
769 			//  Volume - New overall volume level to be used, as an amplitude factor.
770 			//  OperationSet - Used to identify this call as part of a deferred batch.
771 			*/
772 			HRESULT SetVolume (float Volume,
773 								UINT32 OperationSet = XAUDIO2_COMMIT_NOW);
774 
775 			/* NAME: IXAudio2Voice::GetVolume
776 			// DESCRIPTION: Obtains this voice's current overall volume level.
777 			//
778 			// ARGUMENTS:
779 			//  pVolume: Returns the voice's current overall volume level.
780 			*/
781 			void GetVolume (float* pVolume);
782 
783 			/* NAME: IXAudio2Voice::SetChannelVolumes
784 			// DESCRIPTION: Sets this voice's per-channel volume levels.
785 			//
786 			// ARGUMENTS:
787 			//  Channels - Used to confirm the voice's channel count.
788 			//  pVolumes - Array of per-channel volume levels to be used.
789 			//  OperationSet - Used to identify this call as part of a deferred batch.
790 			*/
791 			HRESULT SetChannelVolumes (UINT32 Channels, const (float)* pVolumes,
792 											UINT32 OperationSet = XAUDIO2_COMMIT_NOW);
793 
794 			/* NAME: IXAudio2Voice::GetChannelVolumes
795 			// DESCRIPTION: Returns this voice's current per-channel volume levels.
796 			//
797 			// ARGUMENTS:
798 			//  Channels - Used to confirm the voice's channel count.
799 			//  pVolumes - Returns an array of the current per-channel volume levels.
800 			*/
801 			void GetChannelVolumes (UINT32 Channels, float* pVolumes);
802 
803 			/* NAME: IXAudio2Voice::SetOutputMatrix
804 			// DESCRIPTION: Sets the volume levels used to mix from each channel of this
805 			//              voice's output audio to each channel of a given destination
806 			//              voice's input audio.
807 			//
808 			// ARGUMENTS:
809 			//  pDestinationVoice - The destination voice whose mix matrix to change.
810 			//  SourceChannels - Used to confirm this voice's output channel count
811 			//   (the number of channels produced by the last effect in the chain).
812 			//  DestinationChannels - Confirms the destination voice's input channels.
813 			//  pLevelMatrix - Array of [SourceChannels * DestinationChannels] send
814 			//   levels.  The level used to send from source channel S to destination
815 			//   channel D should be in pLevelMatrix[S + SourceChannels * D].
816 			//  OperationSet - Used to identify this call as part of a deferred batch.
817 			*/
818 			HRESULT SetOutputMatrix (IXAudio2Voice pDestinationVoice,
819 										UINT32 SourceChannels, UINT32 DestinationChannels,
820 										const (float)* pLevelMatrix,
821 										UINT32 OperationSet = XAUDIO2_COMMIT_NOW);
822 	
823 			/* NAME: IXAudio2Voice::GetOutputMatrix
824 			// DESCRIPTION: Obtains the volume levels used to send each channel of this
825 			//              voice's output audio to each channel of a given destination
826 			//              voice's input audio.
827 			//
828 			// ARGUMENTS:
829 			//  pDestinationVoice - The destination voice whose mix matrix to obtain.
830 			//  SourceChannels - Used to confirm this voice's output channel count
831 			//   (the number of channels produced by the last effect in the chain).
832 			//  DestinationChannels - Confirms the destination voice's input channels.
833 			//  pLevelMatrix - Array of send levels, as above.
834 			*/
835 			void GetOutputMatrix (IXAudio2Voice pDestinationVoice,
836 									UINT32 SourceChannels, 
837 									UINT32 DestinationChannels,
838 									float* pLevelMatrix);
839 
840 			/* NAME: IXAudio2Voice::DestroyVoice
841 			// DESCRIPTION: Destroys this voice, stopping it if necessary and removing
842 			//              it from the XAudio2 graph.
843 			*/
844 			void DestroyVoice ();
845 	}
846 
847 
848 	/**************************************************************************
849 	*
850 	* IXAudio2SourceVoice: Source voice management interface.
851 	*
852 	**************************************************************************/
853 
854 	extern(C++) interface IXAudio2SourceVoice : IXAudio2Voice
855 	{
856 		extern(Windows):
857 		
858 		// NAME: IXAudio2SourceVoice::Start
859 		// DESCRIPTION: Makes this voice start consuming and processing audio.
860 		//
861 		// ARGUMENTS:
862 		//  Flags - Flags controlling how the voice should be started.
863 		//  OperationSet - Used to identify this call as part of a deferred batch.
864 		//
865 		HRESULT Start (UINT32 Flags = 0, UINT32 OperationSet = XAUDIO2_COMMIT_NOW);
866 
867 		// NAME: IXAudio2SourceVoice::Stop
868 		// DESCRIPTION: Makes this voice stop consuming audio.
869 		//
870 		// ARGUMENTS:
871 		//  Flags - Flags controlling how the voice should be stopped.
872 		//  OperationSet - Used to identify this call as part of a deferred batch.
873 		//
874 		HRESULT Stop (UINT32 Flags = 0, UINT32 OperationSet = XAUDIO2_COMMIT_NOW);
875 
876 		// NAME: IXAudio2SourceVoice::SubmitSourceBuffer
877 		// DESCRIPTION: Adds a new audio buffer to this voice's input queue.
878 		//
879 		// ARGUMENTS:
880 		//  pBuffer - Pointer to the buffer structure to be queued.
881 		//  pBufferWMA - Additional structure used only when submitting XWMA data.
882 		//
883 		HRESULT SubmitSourceBuffer (const (XAUDIO2_BUFFER)* pBuffer, const (XAUDIO2_BUFFER_WMA)* pBufferWMA = null);
884 
885 		// NAME: IXAudio2SourceVoice::FlushSourceBuffers
886 		// DESCRIPTION: Removes all pending audio buffers from this voice's queue.
887 		//
888 		HRESULT FlushSourceBuffers ();
889 
890 		// NAME: IXAudio2SourceVoice::Discontinuity
891 		// DESCRIPTION: Notifies the voice of an intentional break in the stream of
892 		//              audio buffers (e.g. the end of a sound), to prevent XAudio2
893 		//              from interpreting an empty buffer queue as a glitch.
894 		//
895 		HRESULT Discontinuity ();
896 
897 		// NAME: IXAudio2SourceVoice::ExitLoop
898 		// DESCRIPTION: Breaks out of the current loop when its end is reached.
899 		//
900 		// ARGUMENTS:
901 		//  OperationSet - Used to identify this call as part of a deferred batch.
902 		//
903 		HRESULT ExitLoop (UINT32 OperationSet = XAUDIO2_COMMIT_NOW);
904 
905 		// NAME: IXAudio2SourceVoice::GetState
906 		// DESCRIPTION: Returns the number of buffers currently queued on this voice,
907 		//              the pContext value associated with the currently processing
908 		//              buffer (if any), and other voice state information.
909 		//
910 		// ARGUMENTS:
911 		//  pVoiceState - Returns the state information.
912 		//
913 		void GetState (XAUDIO2_VOICE_STATE* pVoiceState); // may differ with DirectX versions
914 
915 		// NAME: IXAudio2SourceVoice::SetFrequencyRatio
916 		// DESCRIPTION: Sets this voice's frequency adjustment, i.e. its pitch.
917 		//
918 		// ARGUMENTS:
919 		//  Ratio - Frequency change, expressed as source frequency / target frequency.
920 		//  OperationSet - Used to identify this call as part of a deferred batch.
921 		//
922 		HRESULT SetFrequencyRatio (float Ratio,
923 								   UINT32 OperationSet = XAUDIO2_COMMIT_NOW);
924 
925 		// NAME: IXAudio2SourceVoice::GetFrequencyRatio
926 		// DESCRIPTION: Returns this voice's current frequency adjustment ratio.
927 		//
928 		// ARGUMENTS:
929 		//  pRatio - Returns the frequency adjustment.
930 		//
931 		void GetFrequencyRatio (float* pRatio);
932 
933 		// NAME: IXAudio2SourceVoice::SetSourceSampleRate
934 		// DESCRIPTION: Reconfigures this voice to treat its source data as being
935 		//              at a different sample rate than the original one specified
936 		//              in CreateSourceVoice's pSourceFormat argument.
937 		//
938 		// ARGUMENTS:
939 		//  UINT32 - The intended sample rate of further submitted source data.
940 		//
941 		HRESULT SetSourceSampleRate (UINT32 NewSourceSampleRate);
942 	}
943 
944 	/**************************************************************************
945 	*
946 	* IXAudio2SubmixVoice: Submixing voice management interface.
947 	*
948 	**************************************************************************/
949 
950 	interface IXAudio2SubmixVoice : IXAudio2Voice
951 	{
952 		// There are currently no methods specific to submix voices.
953 	}
954 
955 
956 	/**************************************************************************
957 	*
958 	* IXAudio2MasteringVoice: Mastering voice management interface.
959 	*
960 	**************************************************************************/
961 
962 	interface IXAudio2MasteringVoice : IXAudio2Voice
963 	{
964 		version(XAUDIO_2_8)
965 			HRESULT GetChannelMask(DWORD* pChannelmask);
966 		else version(XAUDIO_2_9)
967 			HRESULT GetChannelMask(DWORD* pChannelmask);
968 	}
969 
970 
971 	/**************************************************************************
972 	*
973 	* IXAudio2EngineCallback: Client notification interface for engine events.
974 	*
975 	* REMARKS: Contains methods to notify the client when certain events happen
976 	*          in the XAudio2 engine.  This interface should be implemented by
977 	*          the client.  XAudio2 will call these methods via the interface
978 	*          pointer provided by the client when it calls XAudio2Create or
979 	*          IXAudio2::Initialize.
980 	*
981 	**************************************************************************/
982 
983 	extern(C++) interface IXAudio2EngineCallback
984 	{
985 		extern(Windows):
986 		// Called by XAudio2 just before an audio processing pass begins.
987 		void OnProcessingPassStart ();
988 
989 		// Called just after an audio processing pass ends.
990 		void OnProcessingPassEnd ();
991 
992 		// Called in the event of a critical system error which requires XAudio2
993 		// to be closed down and restarted.  The error code is given in Error.
994 		void OnCriticalError (HRESULT Error);
995 	}
996 
997 
998 	/**************************************************************************
999 	*
1000 	* IXAudio2VoiceCallback: Client notification interface for voice events.
1001 	*
1002 	* REMARKS: Contains methods to notify the client when certain events happen
1003 	*          in an XAudio2 voice.  This interface should be implemented by the
1004 	*          client.  XAudio2 will call these methods via an interface pointer
1005 	*          provided by the client in the IXAudio2::CreateSourceVoice call.
1006 	*
1007 	**************************************************************************/
1008 
1009 	extern(C++) interface IXAudio2VoiceCallback
1010 	{
1011 		// Called just before this voice's processing pass begins.
1012 		void OnVoiceProcessingPassStart (UINT32 BytesRequired);
1013 
1014 		// Called just after this voice's processing pass ends.
1015 		void OnVoiceProcessingPassEnd ();
1016 
1017 		// Called when this voice has just finished playing a buffer stream
1018 		// (as marked with the XAUDIO2_END_OF_STREAM flag on the last buffer).
1019 		void OnStreamEnd ();
1020 
1021 		// Called when this voice is about to start processing a new buffer.
1022 		void OnBufferStart (void* pBufferContext);
1023 
1024 		// Called when this voice has just finished processing a buffer.
1025 		// The buffer can now be reused or destroyed.
1026 		void OnBufferEnd (void* pBufferContext);
1027 
1028 		// Called when this voice has just reached the end position of a loop.
1029 		void OnLoopEnd (void* pBufferContext);
1030 
1031 		// Called in the event of a critical error during voice processing,
1032 		// such as a failing xAPO or an error from the hardware XMA decoder.
1033 		// The voice may have to be destroyed and re-created to recover from
1034 		// the error.  The callback arguments report which buffer was being
1035 		// processed when the error occurred, and its HRESULT code.
1036 		void OnVoiceError (void* pBufferContext, HRESULT Error);
1037 	}
1038 
1039 	version (XAUDIO2_HELPER_FUNCTIONS)
1040 	{
1041 
1042 		// Calculate the argument to SetVolume from a decibel value
1043 		float XAudio2DecibelsToAmplitudeRatio(float Decibels)
1044 		{
1045 			return pow(10.0f, Decibels / 20.0f);
1046 		}
1047 
1048 		// Recover a volume in decibels from an amplitude factor
1049 		float XAudio2AmplitudeRatioToDecibels(float Volume)
1050 		{
1051 			if (Volume == 0)
1052 			{
1053 				return -3.402823466e+38f; // Smallest float value (-FLT_MAX)
1054 			}
1055 			return 20.0f * log10(Volume);
1056 		}
1057 
1058 		// Calculate the argument to SetFrequencyRatio from a semitone value
1059 		float XAudio2SemitonesToFrequencyRatio(float Semitones)
1060 		{
1061 			// FrequencyRatio = 2 ^ Octaves
1062 			//                = 2 ^ (Semitones / 12)
1063 			return pow(2.0f, Semitones / 12.0f);
1064 		}
1065 
1066 		// Recover a pitch in semitones from a frequency ratio
1067 		float XAudio2FrequencyRatioToSemitones(float FrequencyRatio)
1068 		{
1069 			// Semitones = 12 * log2(FrequencyRatio)
1070 			//           = 12 * log2(10) * log10(FrequencyRatio)
1071 			return 39.86313713864835f * log10(FrequencyRatio);
1072 		}
1073 
1074 		// Convert from filter cutoff frequencies expressed in Hertz to the radian
1075 		// frequency values used in XAUDIO2_FILTER_PARAMETERS.Frequency.  Note that
1076 		// the highest CutoffFrequency supported is SampleRate/6.  Higher values of
1077 		// CutoffFrequency will return XAUDIO2_MAX_FILTER_FREQUENCY.
1078 		float XAudio2CutoffFrequencyToRadians(float CutoffFrequency, UINT32 SampleRate)
1079 		{
1080 			if (cast(UINT32)(CutoffFrequency * 6.0f) >= SampleRate)
1081 			{
1082 				return XAUDIO2_MAX_FILTER_FREQUENCY;
1083 			}
1084 			return 2.0f * sin(cast(float)PI * CutoffFrequency / SampleRate);
1085 		}
1086 
1087 		// Convert from radian frequencies back to absolute frequencies in Hertz
1088 		float XAudio2RadiansToCutoffFrequency(float Radians, float SampleRate)
1089 		{
1090 			return SampleRate * asin(Radians / 2.0f) / cast(float)PI;
1091 		}
1092 
1093 	}
1094 
1095 	/**************************************************************************
1096 	*
1097 	* XAudio2Create: Top-level function that creates an XAudio2 instance.
1098 	*
1099 	* On Windows this is just an inline function that calls CoCreateInstance
1100 	* and Initialize.  The arguments are described above, under Initialize,
1101 	* except that the XAUDIO2_DEBUG_ENGINE flag can be used here to select
1102 	* the debug version of XAudio2.
1103 	*
1104 	* On Xbox, this function is implemented in the XAudio2 library, and the
1105 	* XAUDIO2_DEBUG_ENGINE flag has no effect; the client must explicitly
1106 	* link with the debug version of the library to obtain debug behavior.
1107 	*
1108 	**************************************************************************/
1109 
1110 	version(XBOX) 
1111 	{
1112 
1113 		STDAPI XAudio2Create(IXAudio2* ppXAudio2, UINT32 Flags = 0,
1114 							 XAUDIO2_PROCESSOR XAudio2Processor = XAUDIO2_DEFAULT_PROCESSOR);
1115 	}
1116 	else // Windows
1117 	{
1118 		extern(Windows):
1119 		version(DXSDK_2010_6)
1120 			HRESULT XAudio2Create(out IXAudio2 ppXAudio2, UINT32 Flags = 0,
1121 								  XAUDIO2_PROCESSOR XAudio2Processor = XAUDIO2_DEFAULT_PROCESSOR)
1122 		{
1123 			// Instantiate the appropriate XAudio2 engine
1124 			IXAudio2 pXAudio2;
1125 
1126 			HRESULT hr = CoCreateInstance((Flags & XAUDIO2_DEBUG_ENGINE) ? &IID_XAudio2_Debug : &IID_XAudio2,
1127 
1128 			null, CLSCTX_INPROC_SERVER, &IID_IXAudio2, cast(void**)&pXAudio2);
1129 			if (SUCCEEDED(hr))
1130 			{
1131 				hr = pXAudio2.Initialize(Flags, XAudio2Processor);
1132 
1133 				if (SUCCEEDED(hr))
1134 				{
1135 					ppXAudio2 = pXAudio2;
1136 				}
1137 				else
1138 				{
1139 					pXAudio2.Release();
1140 				}
1141 			}
1142 
1143 			return hr;
1144 		}
1145 		else version(XAUDIO_2_8)
1146 		{
1147 			HRESULT XAudio2Create(out IXAudio2 ppXAudio2, UINT32 Flags = 0,
1148 					XAUDIO2_PROCESSOR XAudio2Processor = XAUDIO2_DEFAULT_PROCESSOR);
1149 		}
1150 		else version(XAUDIO_2_9)
1151 		{
1152 			HRESULT XAudio2Create(out IXAudio2 ppXAudio2, UINT32 Flags = 0,
1153 					XAUDIO2_PROCESSOR XAudio2Processor = XAUDIO2_DEFAULT_PROCESSOR);
1154 		}
1155 
1156 	}
1157 }